# coding:utf-8
# writingtime: 2022-8-2
# reference: https://doi.org/10.1007/s40815-021-01243-2

from DistanceFunction.euclidean import Euclidean


class XB:
    @staticmethod
    def getresult(dataList, membershipMatrix, clusterCenter, m=2, a=2):
        """
        function: XieBeni评价函数
        :param dataList: 样本向量
        :param membershipMatrix: 评价矩阵
        :param clusterCenter: 中心点向量
        :param m: 聚合参数
        :return: XieBeni评价值
        """
        sum1 = 0
        temp_matrix = []
        for i in range(len(clusterCenter)):
            li_temp = []
            for j in range(len(dataList)):
                temp = Euclidean.getresult(dataList[j], clusterCenter[i]) ** 2
                if i != j:
                    li_temp.append(temp)
                sum1 += (membershipMatrix[i][j] ** m) * temp
            temp_matrix.append(li_temp)
        minvalue = min(min(i) for i in temp_matrix)
        result = sum1 / (len(dataList) * minvalue)
        return result
